// weixinmao_house/pages/agentdetail/index.js
var R_htmlToWxml = require('../../resource/js/htmlToWxml.js');//引入公共方法
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    title: '',
    tel:'',
    pid:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    wx.setNavigationBarTitle({
      title: wx.getStorageSync('companyinfo').name,
    })

    if (this.data.id > 0) {
      var id = this.data.id;
    } else {
      var id = e.id;
      this.data.id = e.id;
    }

    var that = this;
    //初始化导航数据
    app.util.request({
      'url': 'entry/wxapp/getagentdetail',
      data: { id: id },
      success: function (res) {
        if (!res.data.message.errno) {

       //   var newsDetail;
        //  newsDetail = R_htmlToWxml.html2json(res.data.data.list.content);
          that.data.title = res.data.data.list.name + '-' + wx.getStorageSync('companyinfo').name;
          that.data.tel = res.data.data.list.tel;
          wx.setNavigationBarTitle({
            title: that.data.title,
          })
           console.log(res.data.data.oldhouselist);
          that.setData({
            data: res.data.data.list,
            list: res.data.data.oldhouselist,
            activeCategoryId:1
           // content: newsDetail
          })
        }
      },
      complete: function () {


        wx.hideNavigationBarLoading(); //完成停止加载
        wx.stopPullDownRefresh();
      }
    });
  },
  tabClick: function (e) {


    var pid = e.currentTarget.id;
    
    var that = this;
    that.data.pid = pid;
    // var WxParse = WxParse;
    //初始化导航数据
    var tel = that.data.tel;
    app.util.request({
      'url': 'entry/wxapp/getagenthouse',
      data: { pid: pid,tel:tel },
      success: function (res) {
        if (!res.data.message.errno) {

          that.setData({
            list: res.data.data.houselist,
            activeCategoryId: pid
          })

        }
      }
    });
  }, toHouseDetail: function (e) {
    var id = e.currentTarget.dataset.id;
    var pid = this.data.pid;
    if(pid == 1)
      {
    wx.navigateTo({
      url: "/weixinmao_house/pages/oldhousedetail/index?id=" + id
    })
      }else{
      wx.navigateTo({
        url: "/weixinmao_house/pages/lethousedetail/index?id=" + id
      })

      }

  }
  ,
  doCall: function (e) {
    console.log(e.currentTarget);
    var tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel, //此号码并非真实电话号码，仅用于测试
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.onLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.data.title,
      path: '/weixinmao_house/pages/agentdetail/index?id=' + this.data.id
    }
  }
})